package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 入口类
 * 通过改造入口类实现首页映射：继承WebMvcConfigurerAdapter类，并重写addViewControllers方法
 */
@SpringBootApplication
public class Starter extends WebMvcConfigurerAdapter {
    public static void main(String[] args) {
        SpringApplication.run(Starter.class, args);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        String indexViewName = "index";
        registry.addViewController("/").setViewName(indexViewName);
        registry.addViewController("/index").setViewName(indexViewName);
        registry.addViewController("/page/index").setViewName(indexViewName);
        // 设置优先级
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
        super.addViewControllers(registry);
    }
}
